home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_05 / ALLISON.ZIP / DATE3.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-24  |  704 b   |  30 lines

  1. LISTING 8 - Implementation for the Date class
  2. // date3.cpp
  3.  
  4. #include <stdio.h>
  5. #include "date3.h"
  6.  
  7. const char * Date::month_text[13] =
  8.     {"Bad month", "January", "February", "March", "April",
  9.      "May", "June", "July", "August", "September",
  10.      "October", "November", "December"};
  11.  
  12. Date::Date(int m, int d, int y) : month(m), day(d), year(y)
  13. {}
  14.  
  15. char * Date::format(char *buf) const
  16. {
  17.     sprintf(buf,"%s %d %d",month_text[month],day,year);
  18.     return buf;
  19. }
  20.  
  21. int Date::compare(const Date & dp2) const
  22. {
  23.     int result = year - dp2.year;
  24.     if (result == 0)
  25.         result = month - dp2.month;
  26.     if (result == 0)
  27.         result = day - dp2.day;
  28.     return result;
  29. }
  30.